﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;


namespace Marmat.Forms
{
    [Designer("Marmat.Forms.Design.MemoBoxDesigner")]
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(DevExpress.XtraEditors.MemoEdit))]
    public partial class MemoBox : EditControl, IRequiredComponentSupport
    {
        public MemoBox()
        {

            // 此调用是设计器所必需的。
            this.InitializeComponent();

            // 在 InitializeComponent() 调用之后添加任何初始化。
            this.BaseEdit = this.MemoEdit1;
            this.BaseEdit.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Default;
            this.CaptionTextAlign = ContentAlignment.TopRight;
        }

        public override ContentAlignment CaptionTextAlign
        {
            get => base.CaptionTextAlign;
            set => base.CaptionTextAlign = value;
        }

        /// <summary>
        /// 获取或设置编辑器的值。
        /// </summary>
        [DefaultValue("")]
        public new string Value
        {
            get
            {
                var Result = base.Value;
                if (ReferenceEquals(Result, DBNull.Value))
                {
                    Result = null;
                }
                return Convert.ToString(Result);
            }
            set => base.Value = value;
        }

        /// <summary>
        /// 获取或设置文本框的水印文本。
        /// </summary>
        /// <returns></returns>
        [DefaultValue("")]
        [Category("行为")]
        [Description("获取或设置文本框的水印文本。")]
        public virtual string WatermarkText
        {
            get => this.MemoEdit1.Properties.NullValuePrompt;
            set => this.MemoEdit1.Properties.NullValuePrompt = value;
        }

        public new void ResetCaptionTextAlign()
        {
            this.CaptionTextAlign = ContentAlignment.TopRight;
        }

        public bool Verify()
        {
            return !string.IsNullOrEmpty(this.Value);
        }

        public virtual void OpenStyle()
        {
            this.BaseEdit.BackColor = Color.FromArgb(199, 237, 204);
            this.Invalidate();
        }

        public virtual void CloseStyle()
        {
            this.BaseEdit.BackColor = this.BackColor;
            this.Invalidate();
        }

        protected new bool ShouldSerializeCaptionTextAlign()
        {
            return !(this.CaptionTextAlign == ContentAlignment.TopRight);
        }
    }
}